package cn.lds.healthj377.controller;

import cn.lds.healthj377.domain.ExamRecord;
import cn.lds.healthj377.domain.User;
import cn.lds.healthj377.dto.ResponseDTO;
import cn.lds.healthj377.service.ExamRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;


@Controller
@RequestMapping("exam_record")
public class ExamRecordController {


    private static final Logger log = LoggerFactory.getLogger(ExamRecordController.class);
    @Autowired
    private ExamRecordService examRecordService;


    @RequestMapping("show_report_id")
    public String showReport(Integer id,Model model){
        ResponseDTO<ExamRecord> examRecordResponseDTO = examRecordService.selectExamRecordById(id);
        model.addAttribute("result",examRecordResponseDTO);

        return "show_exam_report";
    }


    @RequestMapping("add_exam_record/{id}")
    public String addExamRecord(@PathVariable Integer id, Model model){

        log.info("log:{}",id);
        model.addAttribute("app_id",id);
        return "add_exam_record";
    }

    @RequestMapping("do_add_exam_record")
    public String doAddExamRecord(ExamRecord examRecord, HttpSession session){

        User loginUser = (User) session.getAttribute("loginUser");
        examRecord.setCreateBy(loginUser.getId());
        log.info("examRecord:{}",examRecord);
        examRecordService.addExamRecord(examRecord);
        //重定向到确认体检完成路径
        return "redirect:/appointment_record/confirm/" + examRecord.getAppointmentId();
    }
}
